package com.ruoyi.hospital.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.hospital.domain.HosCase;
import com.ruoyi.hospital.service.IHosCaseService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 病例信息Controller
 * 
 * @author ruoyi
 * @date 2024-01-06
 */
@RestController
@RequestMapping("/hospital/case")
public class HosCaseController extends BaseController
{
    @Autowired
    private IHosCaseService hosCaseService;

    /**
     * 查询病例信息列表
     */
    @PreAuthorize("@ss.hasPermi('hospital:case:list')")
    @GetMapping("/list")
    public TableDataInfo list(HosCase hosCase)
    {
        startPage();
        List<HosCase> list = hosCaseService.selectHosCaseList(hosCase);
        return getDataTable(list);
    }

    /**
     * 导出病例信息列表
     */
    @PreAuthorize("@ss.hasPermi('hospital:case:export')")
    @Log(title = "病例信息", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, HosCase hosCase)
    {
        List<HosCase> list = hosCaseService.selectHosCaseList(hosCase);
        ExcelUtil<HosCase> util = new ExcelUtil<HosCase>(HosCase.class);
        util.exportExcel(response, list, "病例信息数据");
    }

    /**
     * 获取病例信息详细信息
     */
    @PreAuthorize("@ss.hasPermi('hospital:case:query')")
    @GetMapping(value = "/{caseId}")
    public AjaxResult getInfo(@PathVariable("caseId") Long caseId)
    {
        return success(hosCaseService.selectHosCaseByCaseId(caseId));
    }

    /**
     * 新增病例信息
     */
    @PreAuthorize("@ss.hasPermi('hospital:case:add')")
    @Log(title = "病例信息", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody HosCase hosCase)
    {
        return toAjax(hosCaseService.insertHosCase(hosCase));
    }

    /**
     * 修改病例信息
     */
    @PreAuthorize("@ss.hasPermi('hospital:case:edit')")
    @Log(title = "病例信息", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody HosCase hosCase)
    {
        return toAjax(hosCaseService.updateHosCase(hosCase));
    }

    /**
     * 删除病例信息
     */
    @PreAuthorize("@ss.hasPermi('hospital:case:remove')")
    @Log(title = "病例信息", businessType = BusinessType.DELETE)
	@DeleteMapping("/{caseIds}")
    public AjaxResult remove(@PathVariable Long[] caseIds)
    {
        return toAjax(hosCaseService.deleteHosCaseByCaseIds(caseIds));
    }
}
